package com.example.mybatis_plus_use.mapper;

import com.example.mybatis_plus_use.entity.Orders;
import com.example.mybatis_plus_use.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zjh
 * @since 2025-01-07
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {



    //用户表的一对多查询
    @Select("select * from user where id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "email", column = "email"),
            //以上是属性名和列名对应，以下是关系和列名对应
            @Result(property = "orderList", column = "id",//这里的colomun和前面的orderlist没什么关系，
                    javaType = List.class,                //主要是给下面的方法传值用的
                    many = @Many(select = "com.example.mybatis_plus_use.mapper.OrdersMapper.GetAllOrdersByUserId"))
    })                          //这个是OrdersMapper的GetAllOrdersByUserId方法，包名字要准确
    List<User> GetUserAndOrderDetailByid(@Param("id")Integer id);


}
